<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link   href="../../resource/layui2.6.8/css/layui.css" rel="stylesheet">
    <script  src="../../resource/js/jquery2.2.js"></script>
    <script  src="../../resource/layui2.6.8/layui.js"></script>
    <script  src="../../resource/layui2.6.8/layui.custom.js"></script>
    <script  src="../../resource/js/action.js"></script>
</head>
<body>
<table class="layui-hide" id="rendertable" lay-filter="rendertable"></table>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="downAll">打包下载</button>
<!--        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="bindAllCompany">工具栏2</button>-->
    </div>
</script>
</body>
<script>
    table.render({
        elem: '#rendertable'
        , url: '/downFileTaskLink/page.do?id='+getPathParam("id")
        , where: {}
        , response: {
            statusCode: 200 //规定成功的状态码，默认：0
        }
        // ,page: false
        , parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.records //解析数据列表
            };
        }
        , toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
        , title: '任务数据'
        , defaultToolbar: false
        , cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        , cols: [[
            {type: 'checkbox', fixed: 'left'}
            , {field: 'taskLink', title: '资源路径',templet:function (row) {
                return `<a target="_blank" href="${row.taskLink}">${row.taskLink}</a>`
                }}
            , {field: 'taskStatus', title: '资源状态'}
            , {title: '操作', templet:function (row) {
                    console.log(row)
                    let name=row.taskLink.substring(row.taskLink.indexOf("/")+1)
      return `<a style="color: #1c7430;cursor: pointer" download="${name}" href="/downFileTaskLink/download.do?id=${row.id}">下载</a>`
                }}
        ]]
        , page: true
    });
    var active = {
        downAll(){
           let url= '/downFileTaskLink/downAll.do?taskId='+getPathParam("id")
            window.open(url)
        },
        reloadTable(){
            table.reload('rendertable')
        },
        add(){
            layer.open({
                type: 2,
                title: "新增任务",
                shadeClose:true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['80%', '80%'],
                btn:["保存"],
                content: "add.html",
                yes:function(index){
                    frameCallback(index,(res)=>{
                        jsonAction("/downFileTask/add.do",res,(res)=>{
                            if (res.code == 200) {
                                layer.msg("保存成功")
                                active.reloadTable()
                            }

                        })
                        console.log(res)
                    })
                    layer.close(index)
                },
            });

        },
        getResourceList(row){
            layer.open({
                type: 2,
                title: "资源列表",
                shadeClose:true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['80%', '80%'],
                btn:["关闭"],
                content: "add.html",
                yes:function(index){
                    layer.close(index)
                },
            });
        },
        download(id){

        }
    }
    $(".layui-btn").on("click", function () {
        var type = $(this).data("type");
        active[type] ? active[type]() : '';
    })
    table.on('toolbar(rendertable)', function (obj) {
        active[obj.event] ? active[obj.event]() : '';
    })
</script>
</html>